<?php
/**
 * Easthv Zend Framework Project
 *
 *
 * LICENSE:
 *
 * @category   Zend
 * @package    Easthv_Controller
 * @copyright  Copyright (c) 2009-2010 Easthv Team @ East Hui Van Business Consulting Co., Ltd.(http://www.easthv.com)
 * @license    http://framework.zend.com/license/   BSD License
 * @version    1.0
 * @link       http://www.easthv.com
 * @since      1.0
*/

/**
 * Error Controller.
 * 
 * @uses       Easthv_Controller_Basic
 * @category   Zend
 * @package    Easthv_Controller
 * @subpackage Controller
 * @copyright  Copyright (c) 2009-2010 Easthv Team @ East Hui Van Business Consulting Co., Ltd.(http://www.easthv.com)
 * @license    http://framework.zend.com/license/   BSD License
 * @version    1.0
 * @link       http://www.easthv.com
 * @since      1.0
 * @deprecated
 */
class ErrorController extends Zend_Controller_Action
{


    /**
     * Error Hander of system
     *
     *
     *
     * @access public
     *
     * @return void
     */
    public function errorAction()
    {
        $errors = $this->_getParam('error_handler');
        $exceptions = $this->getResponse()->getException();
        $exceptions = $exceptions[0];
        
        //$this->_helper->layout->setLayout('error');

        $errorCode = $exceptions->getCode();

		$render = null;
		$title = "哎呀，时时价出错了";
		$allowErrorCodes = array(
			400, //Bad Request 
			403, //Forbidden
			405, //Method Not Allowed
			406, //Not Acceptable
			408, //Request Timeout
			409, //Conflict
			415,
		);
        switch ($errorCode) { 

        case Zend_Controller_Plugin_ErrorHandler::EXCEPTION_NO_CONTROLLER:
        case Zend_Controller_Plugin_ErrorHandler::EXCEPTION_NO_ACTION:
        case 404:
            $this->getResponse()->setHttpResponseCode(404)->setRawHeader('HTTP/1.1 404 Not Found');
			$render = "404";
			break;

        case 401:
			$this->getResponse()->setHttpResponseCode(401)->setRawHeader('HTTP/1.1 401 Unauthorized');
			$render = "401";
			break;
    
		default:
			$errorCode = in_array($errorCode, $allowErrorCodes) ? $errorCode : 500;
            $this->getResponse()->setHttpResponseCode($errorCode);
            $this->view->message = 'Application error';
            break;
        }

        $this->view->title = $title;
        $this->view->exception = $errors->exception;
        $this->view->request   = $errors->request;

		if($render) {
			$this->render($render);
		}
    }
}
